//
// Created by xujingyi on 20-11-28.
//
#ifndef _CAMERA_WRAPPER_H_
#define _CAMERA_WRAPPER_H_

#include <additions.h>
#include <opencv2/core/core.hpp>
#include <camera/wrapper_head.h>

#ifdef Windows
#include "camera/CameraApi.h"
#elif defined(Linux) || defined(Darwin)
#include <camera/CameraApi.h>
#endif

class CameraWrapper: public WrapperHead {
    friend void cameraCallback(CameraHandle hCamera, BYTE *pFrameBuffer, tSdkFrameHead* pFrameHead,PVOID pContext);
private:
    const std::string name;
    int mode;

    bool init_done;//是否init成功

    unsigned char* rgb_buffer;
    int camera_cnts;//寻找到的相机个数
    int camera_status,read_status=CAMERA_STATUS_FAILED;//返回的CameraSdkStatus（见camerastatus.h)
    int h_camera;//代表相机身份的CameraHandle相机句柄
    char camera_name[32];

    tSdkCameraDevInfo camera_enum_list[2];//设备信息：系列，名陈等
    tSdkCameraCapbility tCapability;
    tSdkImageResolution tImageResolution; //相机的分辨率描述
    tSdkFrameHead frame_info;
    BYTE *pby_buffer;//camera init时候开辟的buffer
    BYTE *trans_buffer;
    IplImage* iplImage;
    int channel;//通道数

    //RoundQueue<cv::Mat, 2> src_queue;
public:
    int gain;
    int exposure_time_ms;

    CameraWrapper(int exposure, int gain, int camera_mode=1, const std::string &n="NULL");
    ~CameraWrapper() final;

    bool init() final;
    void SetResolution(cv::Size roi, cv::Size offset );
    bool read(cv::Mat& src) final;
    bool readRaw(cv::Mat& src);
    bool readProcessed(cv::Mat& src);
    bool readCallback(cv::Mat& src);
};

// 相机断线重连函数
bool checkReconnect(bool is_camera_connect,WrapperHead *&video);

#endif //_CAMERA_WRAPPER_H_
